package com.zhentao.controller;


import com.zhentao.model.entity.system.SysMenu;
import com.zhentao.model.vo.common.Result;
import com.zhentao.model.vo.common.ResultCodeEnum;
import com.zhentao.service.SysMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/system/sysMenu")
public class SysMenuController {

    @Autowired
    private SysMenuService sysMenuService;

    //    查询所有菜单-递归
    @GetMapping("/findNodes")
    public Result<List<SysMenu>> findNodes() {
        List<SysMenu> list = sysMenuService.findNodes();
        return Result.build(list, ResultCodeEnum.SUCCESS);
    }

    //添加菜单
    @PostMapping("/saveMenu")
    public Result saveMenu(@RequestBody SysMenu sysMenu) {
        sysMenuService.saveMenu(sysMenu);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    //    修改菜单
    @PutMapping("/updateMenuById")
    public Result updateMenuById(@RequestBody SysMenu sysMenu) {
        sysMenuService.updateMenuById(sysMenu);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    //    删除菜单
    @DeleteMapping("/removeMenuById/{id}")
    public Result removeMenuById(@PathVariable Integer id) {
        sysMenuService.removeMenuById(id);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }


}
